package com.chamberlain.equipment.service.impl;

import com.chamberlain.equipment.mapper.SceneEquipmentMapper;
import com.chamberlain.equipment.domain.SceneEquipment;
import com.chamberlain.equipment.service.SceneEquipmentService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 场景设备关联表(SceneEquipment)表服务实现类
 *
 * @author makejava
 * @since 2024-03-25 14:54:07
 */
@Service
public class SceneEquipmentServiceImpl implements SceneEquipmentService {
    @Resource
    private SceneEquipmentMapper sceneEquipmentMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SceneEquipment queryById(Integer id) {
        return this.sceneEquipmentMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param sceneEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SceneEquipment> queryByPage(SceneEquipment sceneEquipment, PageRequest pageRequest) {
        long total = this.sceneEquipmentMapper.count(sceneEquipment);
        return new PageImpl<>(this.sceneEquipmentMapper.queryAllByLimit(sceneEquipment, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param sceneEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public SceneEquipment insert(SceneEquipment sceneEquipment) {
        this.sceneEquipmentMapper.insert(sceneEquipment);
        return sceneEquipment;
    }

    /**
     * 修改数据
     *
     * @param sceneEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public SceneEquipment update(SceneEquipment sceneEquipment) {
        this.sceneEquipmentMapper.update(sceneEquipment);
        return this.queryById(sceneEquipment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.sceneEquipmentMapper.deleteById(id) > 0;
    }
}
